package com.yueya.common.action;

import java.util.HashMap;
import java.util.Map;

import com.jfinal.aop.Clear;
import com.jfinal.kit.JsonKit;
import com.jfinal.plugin.redis.Redis;
import com.yueya.common.util.DateUtil;
import com.yueya.common.util.UUIDGenerator;

import redis.clients.jedis.Jedis;

public class RedisTestController extends BaseController {

	@Clear
	public void index() {
		Jedis j = Redis.use("redis").getJedis();
		j.select(14);
		
		// j.lpush("6253d77c43fa985ca9d458c70364",
		// "28716d814a22810ab1e11bfd72ae");
		// j.lpush("6253d77c43fa985ca9d458c70364",
		// "223f83134cedb63eacea1d8ef77d");
		// j.lrem("6253d77c43fa985ca9d458c70364",1,
		// "28716d814a22810ab1e11bfd72ae");
		// String msg = Redis.use("db").getName();
		// System.out.println(msg);

		// List msg = j.lrange("6253d77c43fa985ca9d458c70364", 0,
		// j.llen("6253d77c43fa985ca9d458c70364"));
		Map<String, String> map = new HashMap<String, String>();
		map.put("member_id", "82e833374ffd9c2ed2b956083f20");
		map.put("create_time", DateUtil.getDate(DateUtil.timeFormat));
		j.hset("a3b90e264304998eb3d7b8386cb1", "82e833374ffd9c2ed2b956083f20",
				JsonKit.toJson(map));
		map.clear();
		map.put("member_id", "84e5c4f940d7a6efb545c6da8eb7");
		map.put("create_time", DateUtil.getDate(DateUtil.timeFormat));
		j.hset("a3b90e264304998eb3d7b8386cb1", "84e5c4f940d7a6efb545c6da8eb7",
				JsonKit.toJson(map));
		Map<String, String> data = j.hgetAll("a3b90e264304998eb3d7b8386cb1");
		String text = "";
		for (Map.Entry<String, String> entry : data.entrySet()) {
			text += entry.getKey() + "--->" + entry.getValue();
			text += "<br>";
		}
		renderText(text);
	}

	public void testRedis() {
		// 获取redis数据库连接
		Jedis j = Redis.use("db").getJedis();
		// 选择库名
		j.select(4);
		// 存记录
		for (int i = 0; i < 300000l; i++) {
			j.hset(UUIDGenerator.getUUID(), UUIDGenerator.getUUID(), "zgq");
			System.out.println(i);
		}
		renderText("SSS");
	}

}
